package com.huanuo.internetofthings.controller.jasper;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.unicorn.framework.core.ResponseDto;
import org.unicorn.framework.core.SysCode;
import org.unicorn.framework.core.exception.PendingException;

import com.huanuo.internetofthings.service.jasperSimStatistics.facade.JasperSimStatisticsFacadeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * sim卡统计表 前端控制器
 * </p>
 *
 * @author xiebin
 * @since 2018-07-19
 */
@RestController
@RequestMapping({"/jasperSimStatistics"})
@Api(value = "JASPER统计模块", tags = { "JASPER统计模块" })
public class JasperSimStatisticsController {
	
    @Autowired
    private  JasperSimStatisticsFacadeService jasperSimStatisticsFacadeService;
	 /**
     * 统计用户所在组sim卡汇总情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计用户所在组sim卡汇总情况")
	@RequestMapping(value = { "/curMonth" }, method = { RequestMethod.GET })
	public ResponseDto<?> curMonth() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsByGroupNo(userIdentity);
	}
	/**
     * 统计设备组Sim卡每月额外总费用汇总情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计设备组Sim卡每月额外总费用汇总情况")
	@RequestMapping(value = { "/extraTotalCost" }, method = { RequestMethod.GET })
	public ResponseDto<?> extraTotalCost() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsExtraTotalCost(userIdentity);
	}
	/**
     * 统计设备组Sim卡每月流量使用率汇总情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计设备组Sim卡每月流量使用率汇总情况")
	@RequestMapping(value = { "/flowRate" }, method = { RequestMethod.GET })
	public ResponseDto<?> flowRate() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsFlowRate(userIdentity);
	}
	
	/**
     * 统计设备组Sim卡每月流量汇总情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计设备组Sim卡每月流量汇总情况")
	@RequestMapping(value = { "/flowTotal" }, method = { RequestMethod.GET })
	public ResponseDto<?> flowTotal() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsFlowTotalCost(userIdentity);
	}
	/**
     * 统计设备组Sim卡每月总费用汇总情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计设备组Sim卡每月总费用汇总情况")
	@RequestMapping(value = { "/totalCost" }, method = { RequestMethod.GET })
	public ResponseDto<?> totalCost() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsTotalCost(userIdentity);
	}
	
	/**
     *  统计设备组Sim卡每月总套餐费用汇总情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计设备组Sim卡每月总费用汇总情况")
	@RequestMapping(value = { "/totalPackageCost" }, method = { RequestMethod.GET })
	public ResponseDto<?> totalPackageCost() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsTotalPackageCost(userIdentity);
	}
	
	/**
     *  统计设备组Sim卡每月流量共享池总使用情况
     * @return
     * @throws PendingException
     */
	@ApiOperation("统计设备组Sim卡每月流量共享池总使用情况")
	@RequestMapping(value = { "/flowShareRate" }, method = { RequestMethod.GET })
	public ResponseDto<?> statisticsFlowShareRate() throws PendingException {
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		return jasperSimStatisticsFacadeService.statisticsFlowShareRate(userIdentity);
	}
}
